#include "Polygon.h"


CPolygon::CPolygon(int numVertices)
{
	_numVertices = numVertices;
	_vertices = new Vector[_numVertices];
	for (int i=0;i<_numVertices;i++)
		_vertices[i] = Vector();
}

CPolygon::CPolygon(const RECT &rec)
{
	_numVertices = 4;
	_vertices = new Vector[_numVertices];

	_vertices[0] = Vector(rec.left,rec.top);
	_vertices[1] = Vector(rec.right,rec.top);
	_vertices[2] = Vector(rec.right,rec.bottom);
	_vertices[3] = Vector(rec.left,rec.bottom);
}

CPolygon::CPolygon(const CPolygon &polygon)
{
	_numVertices = polygon._numVertices;
	_vertices = new Vector[_numVertices];

	for (int i=0;i<_numVertices;i++)
		_vertices[i] = polygon._vertices[i];
}

CPolygon::~CPolygon(void)
{
	delete[] _vertices;
}

CPolygon &CPolygon::operator=(const CPolygon &polygon)
{
	_numVertices = polygon._numVertices;
	_vertices = new Vector[_numVertices];

	for (int i=0;i<_numVertices;i++)
		_vertices[i] = polygon._vertices[i];
	
	return *this;
}

void CPolygon::setVertice(int index, const Vector &v)
{
	if (index < _numVertices)
		_vertices[index] = v;
}

Vector CPolygon::getVertice(int index)
{
	Vector v = _vertices[index];
	return _vertices[index];
}

bool CPolygon::checkPolygon()
{
	for (int i=0;i<_numVertices;i++)
		if (_vertices[i].isZero())
			return false;
	return true;
}

const int &CPolygon::getLength()
{
	return _numVertices;
}

Vector CPolygon::getFocus()
{
	return Vector((_vertices[0].getX() + _vertices[1].getX())/2,(_vertices[0].getY() + _vertices[3].getY())/2);
}
